var zfgl = function() {
	function initRhz() { //日汇总
		var ractive = new Ractive({
			el: '.container',
			template: "#rhz-template",
			oncomplete: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 1;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 1);
			}
		});

		ractive.on({
			search: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 1;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 1);
			}
		});
	}

	function initRhzaxw() { //日汇总按行为
		var ractive = new Ractive({
			el: '.container',
			template: "#rhzaxw-template",
			oncomplete: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 2;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 2);
				/* 初始化行为列表 */
            	$.ajax({
            		url: Constants.epUrlPath + "common/getXwList",
            		 type: 'get',
                     success: function(data) {
                    	 var ztobj = data;
                    	 var qb="全部";
                    	 var quanbu = [ {
             				"code" : "-1",
             				"codedesc" : qb
             			} ];
                    	data = $.merge(quanbu, ztobj);
             			store.set("JFXW", JSON.stringify(data));
             			selecttextInfo();
             			setWDCode("code_JFXW", -1);
                     }
            	});
			}
		});
		ractive.on({
			search: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.xw = getWDCode("code_JFXW");
				param.flag = 2;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 2);
			}
		});
	}

	function initHqmx() { //获取明细
		var ractive = new Ractive({
			el: '.container',
			template: "#hqmx-template",
			oncomplete: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 3;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 3);
			}
		});
		ractive.on({
			search: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 3;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 3);
			}
		});
	}

	function initZcmx() { //支出明细
		var ractive = new Ractive({
			el: '.container',
			template: "#zcmx-template",
			oncomplete: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 4;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 4);
			}
		});
		ractive.on({
			search: function() {
				var param = {};
				param.starttime = ractive.get('starttime');
				param.endtime = ractive.get('endtime');
				param.flag = 4;
				param.pageSize = Constants.page.pagesize;
				param.currPage = 1;
				searchTable(param, 4);
			}
		});
	}
	return {
		initRhz: function() {
			initRhz();
		},
		initRhzaxw: function() {
			initRhzaxw();
		},
		initHqmx: function() {
			initHqmx();
		},
		initZcmx: function() {
			initZcmx();
		},
		toHqmx: toHqmx,
		toZcmx: toZcmx
	}
}();

function initRhz() {
	zfgl.initRhz();
}

function initRhzaxw() {
	zfgl.initRhzaxw();
}

function initHqmx(){
	zfgl.initHqmx();
}

function initZcmx(){
	zfgl.initZcmx();
}
function toHqmx(s) {
	//zfgl.initHqmx();
	var ractive = new Ractive({
		el: '.container',
		template: "#hqmx-template",
		oncomplete: function() {
			var param = {};
			param.starttime = s;
			param.endtime = s;
			ractive.set("starttime",s);
			ractive.set("endtime",s);
			param.flag = 3;
			param.pageSize = Constants.page.pagesize;
			param.currPage = 1;
			searchTable(param, 3);
		}
	});
}

function toZcmx(s) {
	//zfgl.initZcmx();
	var ractive = new Ractive({
		el: '.container',
		template: "#zcmx-template",
		oncomplete: function() {
			var param = {};
			param.starttime = s;
			param.endtime = s;
			ractive.set("starttime",s);
			ractive.set("endtime",s);
			param.flag = 4;
			param.pageSize = Constants.page.pagesize;
			param.currPage = 1;
			searchTable(param, 4);
		}
	});
}

function getObj(data, flag) {
	if(flag == 1 || flag == 3 || flag == 4) {
		if(data) {
			var obj = {
				starttime: data.starttime,
				endtime: data.endtime,
				currPage: data.currPage,
				flag: data.flag,
				pageSize: data.pageSize
			};
			return obj;
		} else {
			return {};
		}
	} else {
		if(data) {
			var obj = {
				starttime: data.starttime,
				endtime: data.endtime,
				currPage: data.currPage,
				flag: data.flag,
				pageSize: data.pageSize,
				xw:data.xw
			};
			return obj;
		} else {
			return {};
		}
	}
}

function searchTable(obj, flag) {
	var jsonData = getObj(obj, flag);
	loadTable(setTitleI18n(flag), jsonData, flag); //加载表格
}

/* 国际化title */
function setTitleI18n(flag) {
	if(flag == 1) {
		var rq = '日期';
		var jfhq = '获取积分';
		var zcjf = '支出积分';
		var obj = [rq, jfhq, zcjf];
		return obj;
	} else if(flag == 2) {
		var rq = '日期';
		var jfhq = '积分获取/支出行为';
		var zcjf = '获取/支出积分';
		var obj = [rq, jfhq, zcjf];
		return obj;
	} else if(flag == 3) {
		var rq = '日期';
		var jfhq = '获取积分';
		var xxsm = '详细说明';
		var obj = [rq, jfhq, xxsm];
		return obj;
	} else {
		var rq = '日期';
		var jfhq = '支出积分';
		var xxsm = '详细说明';
		var obj = [rq, jfhq, xxsm];
		return obj;
	}
}
/*
 * 加载表格--关联设置
 * */
function loadTable(title, param, flag) {
	var data;
	var url = Constants.epUrlPath + 'zfgl/getJfxxList';
	if(flag == 1) {
		data = [{
			name: 'hqrq',
			width: 100,
			innerhtml: function(opts) {
				return moment(opts.rq).format("YYYY-MM-DD");
			}
		}, {
			name: 'jfhq',
			width: 60,
			innerhtml: function(opts) {
				var d = moment(opts.rq).format("YYYY-MM-DD");
				return "<a href='javascript:void(0)' onclick='toHqmx(\""+d+"\")'>"+opts.hqjf+"</a>";
				//return opts.hqjf;
			}
		}, {
			name: 'zcjf',
			width: 100,
			innerhtml: function(opts) {
				var d = moment(opts.rq).format("YYYY-MM-DD");
				return "<a href='javascript:void(0)' onclick='toZcmx(\""+d+"\")'>"+opts.zcjf+"</a>";
				//return opts.zcjf;
			}
		}];
	} else if(flag == 2) {
        data = [{
			name: 'hqrq',
			width: 100,
			innerhtml: function(opts) {
				return moment(opts.rq).format("YYYY-MM-DD");
			}
		}, {
			name: 'jfhq',
			width: 60,
			innerhtml: function(opts) {
				return opts.xwDesc;
			}
		}, {
			name: 'zcjf',
			width: 100,
			innerhtml: function(opts) {
				return opts.jfz;
			}
		}];
	} else if(flag == 3) {
        data = [{
			name: 'hqrq',
			width: 100,
			innerhtml: function(opts) {
				return moment(opts.rq).format("YYYY-MM-DD HH:mm:ss");
			}
		}, {
			name: 'jfhq',
			width: 60,
			innerhtml: function(opts) {
				return opts.jfz;
			}
		}, {
			name: 'xxsm',
			width: 100,
			float: 'left',
			innerhtml: function(opts) {
				var sm = "";
				if(opts.xw=="01"){//登录
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="02"){//签到
					sm=opts.xwDesc+"(消费者："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="03"){//关注产品
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="04"){//关注合作方
					sm=opts.xwDesc+"(消费者："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="05"){//购买产品
					sm=opts.xwDesc+"(订单编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="10"){//分享主页
					sm=opts.xwDesc+"(消费者："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="11"){//分享产品
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="12"){//
					sm=opts.xwDesc+"(订单编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="13"){//发布产品
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="14"){//逆向交易
					sm="退款"+"(订单编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="15"){//积分兑换
					sm=opts.xwDesc+"(兑换编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="16"){//积分抵扣
					sm=opts.xwDesc+"(提现编号："+(opts.bz==null?'':opts.bz)+")";
				}
				return sm;
			}
		}];
	} else {
       data = [{
			name: 'hqrq',
			width: 100,
			innerhtml: function(opts) {
				return moment(opts.rq).format("YYYY-MM-DD HH:mm:ss");
			}
		}, {
			name: 'jfhq',
			width: 60,
			innerhtml: function(opts) {
				return opts.jfz;
			}
		}, {
			name: 'xxsm',
			width: 100,
			float: 'left',
			innerhtml: function(opts) {
				var sm = "";
				if(opts.xw=="01"){//登录
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="02"){//签到
					sm=opts.xwDesc+"(消费者："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="03"){//关注产品
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="04"){//关注合作方
					sm=opts.xwDesc+"(消费者："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="05"){//购买产品
					sm=opts.xwDesc+"(订单编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="10"){//分享主页
					sm=opts.xwDesc+"(消费者："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="11"){//分享产品
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="12"){//
					sm=opts.xwDesc+"(订单编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="13"){//
					sm=opts.xwDesc+"(产品编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="14"){//逆向交易
					sm=opts.xwDesc+"(订单编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="15"){//积分兑换
					sm=opts.xwDesc+"(兑换编号："+(opts.bz==null?'':opts.bz)+")";
				}else if(opts.xw=="16"){//积分抵扣
					sm=opts.xwDesc+"(提现编号："+(opts.bz==null?'':opts.bz)+")";
				}
				return sm;
			}
		}];
	}

	// 绘制出关联设置信息列表
	$("#wd-table").wdGrid({
		url: url,
		colNames: title,
		colModel: data,
		dataType: "GET",
		async: false,
		oddflg: false,
		submitType: "noForm",
		postData: param,
		checkflg: false,
		pager: "#wd-pager",
		rowList: Constants.page.rowList,
		pagesize: Constants.page.pagesize
	});
}
$(document).ready(zfgl.initRhz);